package com.lzh.eventdemo.service;

import com.lzh.eventdemo.entity.Responses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * @Description:
 * @Author: LiuZiHao
 * @Date: 2022/8/26 10:26
 */
@Slf4j
@Service
public class TaskService2 {

    public void getData(DeferredResult<Responses<String>> deferredResult) {

        log.info("调用service异步有返回方法，开始执行...");
        long startTime = System.currentTimeMillis();

        try {
            Thread.sleep(2500L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.info("调用service异步有返回方法，执行结束！！");

        long endTime = System.currentTimeMillis();
        log.info("调用service异步有返回方法总耗时： " + (endTime - startTime) + "ms");

        deferredResult.setResult(new Responses<>(0, "异步处理完成", "SUCCESS"));

    }

}
